package com.mdd.front.controller;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.mdd.common.core.AjaxResult;
import com.mdd.common.entity.BannerSetting;
import com.mdd.common.entity.UserNotice;
import com.mdd.front.LikeFrontThreadLocal;
import com.mdd.front.service.IOtherService;
import com.mdd.front.vo.other.UserNoticeVo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("/api/other")
@Api(tags = "其他相关API")
public class OtherController {

	@Autowired
	private IOtherService otherService;
	
	/**
	 * 	获取banner
	 * @param type		1=APP
	 * @param businessType 1=消息页面
	 * @return
	 */
	@GetMapping("/qryBannerList")
	@ApiOperation(value = "获取消息列表")
	public AjaxResult<List<BannerSetting>> qryBannerList(Integer type,Integer businessType) {
		Integer userId = LikeFrontThreadLocal.getUserId();
		if(null == type) type = 1;
		if(null == businessType) businessType = 1;
		return otherService.qryBannerList(userId, type,businessType); 
	}
	
	@GetMapping("/qrykdNotice")
	@ApiOperation(value = "获取快点消息通知")
	public AjaxResult<UserNotice> qrykdNotice() {
		Integer userId = LikeFrontThreadLocal.getUserId();
		return otherService.qrykdNotice(userId); 
	}
	
	/**
	 * 设置快点消息通知	
	 * @param notice.type		按照顺序默认
	 * @return
	 */
	@PostMapping("/setkdNotice")
	@ApiOperation(value = "设置快点消息通知")
	public AjaxResult<Object> setkdNotice(@RequestBody UserNoticeVo notice) {
		Integer userId = LikeFrontThreadLocal.getUserId();
		if(null == notice || null == notice.getType()) {
			return AjaxResult.failed("请选择数据");
		}
		return otherService.setkdNotice(userId,notice.getType()); 
	}
	
	/**
	 * 设置快点消息通知恢复默认
	 * @param notice.type		1=我是寄件人 2=我是收件人
	 * @return
	 */
	@PostMapping("/setkdNoticeDefault")
	@ApiOperation(value = "设置快点消息通知恢复默认")
	public AjaxResult<Object> setkdNoticeDefault(@RequestBody UserNoticeVo notice) {
		Integer userId = LikeFrontThreadLocal.getUserId();
		if(null == notice || null == notice.getType()) {
			return AjaxResult.failed("请选择数据");
		}
		return otherService.setkdNoticeDefault(userId,notice.getType()); 
	}
}
